package com.ibatisorm.action;

import java.io.IOException;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ibatisorm.common.db.DbConfig;
import com.ibatisorm.dao.Querydao;
import com.ibatisorm.util.DatabaseType;

/**
 * Servlet implementation class Test
 */
public class Test extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Test() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		EnumMap<DbConfig, String> map = new EnumMap<DbConfig, String>(DbConfig.class);
		map.put(DbConfig.driverClass, request.getParameter("driverClass"));
		map.put(DbConfig.jdbcUrl, request.getParameter("jdbcUrl"));
		map.put(DbConfig.user, request.getParameter("user"));
		map.put(DbConfig.password, request.getParameter("password"));
		
		ApplicationContext context = new ClassPathXmlApplicationContext(
		        new String[] {"config/applicationContext.xml"});
		
		Querydao query = (Querydao)context.getBean("query");
		Map map1 = new HashMap(2);
		map1.put("type", DatabaseType.TYPE);
		map1.put("tablename", "T_MTDATA");
		List list = query.getTables();
		System.out.println(list);
		System.out.println(DatabaseType.TYPE);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
	}

}
